#import "CalculatorViewController.h"
#import <Foundation/NSString.h>
#import <Foundation/Foundation.h>

@implementation CalculatorViewController

-(IBAction)penny:(id)sender;
{
	
	NSString *button = [sender titleForState:UIControlStateNormal];
	if ([button isEqualToString:@"Add Penny"])
	{ 
		[displayField setText:[NSString stringWithFormat:@"%ld penny", [current addPenny]]]; 
		[pDisplay setText:[NSString stringWithFormat:@"%ld", [current getPenny]]]; 
		
	}
	else if ([button isEqualToString:@"Minus Penny" ])
	{
		[displayField setText:[NSString stringWithFormat:@"%ld penny", [current decPenny]]];
		[pDisplay setText:[NSString stringWithFormat:@"%ld", [current getPenny]]]; 
		
	}
}


-(IBAction)nickel:(id)sender;
{
	
	NSString *button = [sender titleForState:UIControlStateNormal];
	if ([button isEqualToString:@"Add Nickel"])
	{ 
		[displayField setText:[NSString stringWithFormat:@"%ld nicke", [current addNickel]]]; 
		[nDisplay setText:[NSString stringWithFormat:@"%ld", [current getNickel]]]; 
		
	}
	else if ([button isEqualToString:@"Minus Nickel" ])
	{
		[displayField setText:[NSString stringWithFormat:@"%ld nickel", [current decNickel]]];
		[nDisplay setText:[NSString stringWithFormat:@"%ld", [current getNickel]]]; 
		
	}
}


-(IBAction)dime:(id)sender;
{
	
	NSString *button = [sender titleForState:UIControlStateNormal];
	if ([button isEqualToString:@"Add Dime"])
	{ 
		[displayField setText:[NSString stringWithFormat:@"%ld dime", [current addDime]]]; 
		[dDisplay setText:[NSString stringWithFormat:@"%ld", [current getDime]]]; 
		
	}
	else if ([button isEqualToString:@"Minus Dime" ])
	{
		[displayField setText:[NSString stringWithFormat:@"%ld dime", [current decDime]]];
		[dDisplay setText:[NSString stringWithFormat:@"%ld", [current getDime]]]; 
		
	}
}



-(IBAction)quater:(id)sender;
{
	
	NSString *button = [sender titleForState:UIControlStateNormal];
	if ([button isEqualToString:@"Add Quarter"])
	{ 
		[displayField setText:[NSString stringWithFormat:@"%ld quater", [current addQuater]]]; 
		[qDisplay setText:[NSString stringWithFormat:@"%ld", [current getQuater]]]; 
		
	}
	else if ([button isEqualToString:@"Minus Quarter" ])
	{
		[displayField setText:[NSString stringWithFormat:@"%ld quater", [current decQuater]]];
		[qDisplay setText:[NSString stringWithFormat:@"%ld", [current getQuater]]]; 
		
	}
}


-(IBAction)loonie:(id)sender;
{
	
	NSString *button = [sender titleForState:UIControlStateNormal];
	if ([button isEqualToString:@"Add Loonie"])
	{ 
		[displayField setText:[NSString stringWithFormat:@"%ld loonie", [current addLoonie]]]; 
		[lDisplay setText:[NSString stringWithFormat:@"%ld", [current getLoonie]]]; 
		
	}
	else if ([button isEqualToString:@"Minus Loonie" ])
	{
		[displayField setText:[NSString stringWithFormat:@"%ld loonie", [current decLoonie]]];
		[lDisplay setText:[NSString stringWithFormat:@"%ld", [current getLoonie]]]; 
		
	}
}


-(IBAction)toonie:(id)sender;
{
	
	NSString *button = [sender titleForState:UIControlStateNormal];
	if ([button isEqualToString:@"Add Toonie"])
	{ 
		[displayField setText:[NSString stringWithFormat:@"%ld toonie", [current addToonie]]]; 
		[tDisplay setText:[NSString stringWithFormat:@"%ld", [current getToonie]]]; 
		
	}
	else if ([button isEqualToString:@"Minus Toonie" ])
	{
		[displayField setText:[NSString stringWithFormat:@"%ld toonie", [current decToonie]]];
		[tDisplay setText:[NSString stringWithFormat:@"%ld", [current getToonie]]]; 
		
	}
}



-(IBAction)getAnswer:(id)sender;
{
	
	float answer;
	answer=[current total];
	
	
	if(answer==-2)
	{
	 	[displayField setText:[NSString stringWithFormat:@"Please press [Question] first "]];
		[displayField2 setText:[NSString stringWithFormat:@"To start the game "]];
	}
	else if (answer==-1)
	{
		[displayField setText:[NSString stringWithFormat:@"Your answer is correct"]];
	}
	else
	{
		[displayField setText:[NSString stringWithFormat:@"Your answer is incorrect, total %.2f",answer]];
	}
	
	
}

-(IBAction)random:(id)sender;
{
	
	[pDisplay setText:[NSString stringWithFormat:@"0"]]; 
	[nDisplay setText:[NSString stringWithFormat:@"0"]]; 
	[dDisplay setText:[NSString stringWithFormat:@"0"]]; 
	[qDisplay setText:[NSString stringWithFormat:@"0"]]; 
	[lDisplay setText:[NSString stringWithFormat:@"0"]]; 
	[tDisplay setText:[NSString stringWithFormat:@"0"]]; 
	[displayField setText:[NSString stringWithFormat:@""]];
	[displayField2 setText:[NSString stringWithFormat:@"Make %.2f out of coins", [current randomValue]]];
}


- (void)viewDidLoad {
	current= [CalculatorModel new];
	[super viewDidLoad];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
	// Release anything that's not essential, such as cached data
}


- (void)dealloc {
	[current release];
	[super dealloc];
}

@end
